<template>
  <div class="gzl">
    <div class="search">
      <el-form :inline="true" :model="search" class="demo-form-inline">
        <el-form-item label="输入搜索">
          <el-input
            v-model="search.key"
            placeholder="请输入设备名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="输入时间">
          <el-date-picker
            v-model="search.time"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="chage"
          ></el-date-picker>
        </el-form-item>
        <el-form-item
        >
          <el-button type="primary" @click="onsubmit"
          >查询
          </el-button
          >
        </el-form-item
        >
      </el-form>
      <!--            <el-button class="ebtn" type="warning" @click="dialogVisible = true">新增价目表</el-button>-->
    </div>
    <el-table class="table" stripe :data="tableData" style="width: 100%" height="580">
      <el-table-column type="index" label="序号" align="center" width="70px"/>
      <el-table-column prop="carType" label="汽车品牌/型号" align="center"/>
      <el-table-column prop="carNumber" label="车牌号" align="center"/>
      <el-table-column prop="sanbaoqi" label="三包期" align="center">
        <template v-slot="scope">
          <span v-show="scope.row.sanbaoqi==1">是</span>
          <span v-show="scope.row.sanbaoqi==2">否</span>
        </template>
      </el-table-column>
      <el-table-column prop="guzhangxianxiang" label="故障现象" align="center"/>
      <el-table-column prop="applyTime" label="申请时间" align="center">
        <template v-slot="scope">
          {{formatTime(scope.row.applyTime)}}
        </template>
      </el-table-column>
      <el-table-column prop="shengheStatus" label="状态" align="center">
        <template v-slot="scope">
          <span v-show="scope.row.shengheStatus==1">待审核</span>

          <el-button v-if="scope.row.shengheStatus == 2" type="text" size="medium"
                     @click="getBOhui(scope.row.checkFolwId)">驳回
          </el-button>
<!--          <span v-show="scope.row.shengheStatus==2">驳回</span>-->
          <span v-show="scope.row.shengheStatus==3">待发货</span>
          <span v-show="scope.row.shengheStatus==4">待收货</span>
          <span v-show="scope.row.shengheStatus==5">已收货</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="primary"
            @click="shouhuo(scope.row.shengheMessageId)"
            v-if="scope.row.shengheStatus==4"
          >收货
          </el-button>
          <el-button size="small" type="text" @click="xiangq(scope.row.shengheMessageId)">详情</el-button>
        </template>
      </el-table-column>

    </el-table>
    <div class="pgnt">
      <el-pagination
        background
        layout="prev, pager, next"
        :current-page="current"
        :page-size="pagesize"
        @current-change="handleCurrentChangeqq"
        :page-count="total"
      ></el-pagination>
    </div>
    <!--确认收货-->
    <el-dialog
      title="确认收货"
      :visible.sync="dialogVisible"
      width="50%"
      :modal-append-to-body="false">
      <template>
        <el-table
          :data="listArr"
          style="width: 100%">
          <el-table-column
            type="index"
            label="序号"
            width="180">
          </el-table-column>
          <el-table-column
            label="零件名称"
            width="180">
            <template slot-scope="scope">
              <el-input v-model="scope.row.productName" disabled></el-input>
            </template>
          </el-table-column>
          <el-table-column
            label="零件图号">
            <template slot-scope="scope">
              <el-input v-model="scope.row.productTuhao" disabled></el-input>
            </template>
          </el-table-column>
          <el-table-column
            label="数量">
            <template slot-scope="scope">
              <el-input v-model="scope.row.number" disabled></el-input>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <span slot="footer" class="dialog-footer">
              <el-button type="primary" @click="queren()">确 定</el-button>
              <el-button @click="dialogVisible = false">取 消</el-button>
           </span>
    </el-dialog>
    <!--详情-->
    <el-dialog
      title="申请详情"
      :visible.sync="dialogVisible1"
      width="70%"
      :modal-append-to-body="false">
      <template>
        <el-table
          :data="listArr"
          style="width: 100%">
          <el-table-column
            type="index"
            label="序号"
            width="70%"
          >
          </el-table-column>
          <el-table-column
            prop="productType"
            label="车型"
          >
            <template slot-scope="scope">
              <el-input v-model="scope.row.productType" disabled></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="address"
            label="物料名称">
            <template slot-scope="scope">
              <el-input v-model="scope.row.productName" disabled></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="address"
            label="图号">
            <template slot-scope="scope">
              <el-input v-model="scope.row.productTuhao" disabled></el-input>
            </template>
          </el-table-column>
          <el-table-column
            label="三包期">
            <template slot-scope="scope">
              <el-checkbox :checked="scope.row.sanbaoqian==1" :disabled="scope.row.sanbaoqian !=1"></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column
            prop="address"
            label="价格">
            <template slot-scope="scope">
              <el-input v-model="scope.row.danjia" disabled></el-input>
            </template>
          </el-table-column>
          <el-table-column
            prop="address"
            label="数量">
            <template slot-scope="scope">
              <el-input v-model="scope.row.number" disabled></el-input>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dialogVisible1 = false">确 定</el-button>
          </span>
    </el-dialog>

    <el-dialog
      title="驳回详情"
      :visible.sync="dialogVisible_bohui"
      width="50%"
      :modal-append-to-body="false">
      <ul :data="bohuilist" class="bohuizujian">
        <li>
          <span>审核日期</span>
          <el-input v-model="bohuilist.checkTime" style="width: 70%;" disabled></el-input>
        </li>
        <li>
          <span>审核人</span>
          <el-input v-model="bohuilist.userName" style="width: 70%;" disabled></el-input>
        </li>
        <li>
          <span>驳回理由</span>
          <el-input v-model="bohuilist.bohuiReason" style="width: 70%;" disabled></el-input>
        </li>
      </ul>
      <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="dialogVisible_bohui = false">返 回</el-button>
  </span>
    </el-dialog>
  </div>
</template>
<script>
import axios from 'axios'

export default {
  components: {},
  data() {
    return {
      dialogVisible_bohui: false,
      bohuilist:{
        bohuiReason:"",
        checkTime:"",
        userName:"",
      },
      search: {key: "", start: "", end: ""},
      tableData: [],
      total: 1,
      current: 1,
      pagesize: 10,
      dialogVisible: false,
      dialogVisible1: false,
      radio: "1",
      value: "",
      options: [],
      checked: true,
      listArr: [],
      querId:"",

    };
  },
  //监听属性 类似于data概念",
  computed: {},
  //监控data中的数据变化",
  watch: {},
  //方法集合",
  methods: {
    getBOhui(checkflowId) {
      this.dialogVisible_bohui = true
      axios("/JX_java/procurement/getCheckFlowDetails?checkFlowId=" + checkflowId).then((res) => {
        console.log(res)
        let relse = res.data.data
        this.bohuilist = relse
        console.log(this.bohuilist)
      })
    },

    //时间格式化
    formatTime(data){
      return data==null?"":data.substring(0, 10);
    },
    getList() {
      const json = {
        beginTime: this.search.start,
        endTime: this.search.end,
        key: this.search.key,
        pageNum: this.current,
        pageSize: this.pagesize,
      };
      axios
        .post(
          "/JX_java/site/applyAdmin/getSiteApplyList?siteId=" + this.siteId, json
        ).then((res) => {
        console.log(res.data.data, 11111111111111111111111111)

        const result = res.data.data.content;
        this.tableData = result
        this.total= res.data.data.totalPages
        console.log(this.tableData, 111111)
        // this.clientIdarr = result;
      });
    },

    //详情
    xiangq(id) {
      this.dialogVisible1 = true
      this.getshou(id)
    },
    //收货
    shouhuo(id) {
      this.dialogVisible = true
      this.getshou(id)
    },
    //详情与收货展示
    getshou(id) {
      this.querId=id
      axios
      (
        "/JX_java/site/applyAdmin/getApplyPorductDetails?shengheMessageId=" + id
      ).then((res) => {
        this.listArr = res.data.data

      });
    },
    //确认收货
    queren() {
      axios("/JX_java/site/applyAdmin/updateShengheMessageStatus?shengheMessageId=" + this.querId
      ).then((res) => {
        if (res.data.data == "操作成功") {
          this.$message.success(res.data.data);
          this.dialogVisible = false
          this.getList()
        } else {
          this.$message.error(res.data.data);
        }
      })
    },
    handleCurrentChangeqq(e) {
      this.current = e
      this.getList();
    },
    chage(e) {
      if (e) {
        this.search.start = e[0];
        this.search.end = e[1];
      } else {
        this.search.start = "";
        this.search.end = "";
      }
    },
    onsubmit() {
      this.getList();
    },
  },
  //生命周期 - 创建之前",数据模型未加载,方法未加载,html模板未加载
  beforeCreate() {
  },
  //生命周期 - 创建完成（可以访问当前this实例）",数据模型已加载，方法已加载,html模板已加载,html模板未渲染
  created() {
    this.siteId = JSON.parse(localStorage.getItem("listDataArr")).id
    this.userId = JSON.parse(localStorage.getItem("message")).Id;
    this.getList()
  },
  //生命周期 - 挂载之前",html模板未渲染
  beforeMount() {
  },
  //生命周期 - 挂载完成（可以访问DOM元素）",html模板已渲染
  mounted() {
  },
  //生命周期 - 更新之前",数据模型已更新,html模板未更新
  beforeUpdate() {
  },
  //生命周期 - 更新之后",数据模型已更新,html模板已更新
  updated() {
  },
  //生命周期 - 销毁之前",
  beforeDestroy() {
  },
  destroyed() {
  },
  //生命周期 - 销毁完成",
  //如果页面有keep-alive缓存功能，这个函数会触发",
  activated() {
  },
}
</script>
<style lang="scss" scoped>
.bohuizujian{
  display: flex;
  flex-wrap: wrap;
  li{
    width: 33%;
    padding-top: 10px;
    text-align: center;
    span{
      display: inline-block;
      width: 25%;
    }
  }
}

.gzl {
  padding-left: 10px;
  padding-right: 10px;
  padding-top: 10px;
}

.table {
  margin-bottom: 20px;
}

.pgnt {
  text-align: center;
}

.demo-form-inline {
  display: inline-block;
}

.search {
  height: 50px;
  border-radius: 5px;
  background-color: #fff;
  padding-left: 20px;
  padding-top: 10px;
  margin-bottom: 20px;
  overflow: hidden;
}

.ebtn {
  float: right;
  margin-right: 20px;
}

/deep/ .is-leaf {
  text-align: center;
  background: #fff;
}

.header {
  border-bottom: 1px solid rgb(220, 222, 226);
}

.intermediate {
  border-bottom: 1px solid rgb(220, 222, 226);
  //width: 98%;
  margin: auto;
  padding-bottom: 20px;


  ul {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    color: #909399;
    margin-top: 20px;

    li {

      width: 33%;
      font-size: 14px;
      margin-bottom: 10px;
      text-align: center;

      div {
        margin-top: 5px;
      }

      span {
        display: inline-block;
        width: 25%;
      }
    }
  }
}

.footer-top {
  margin-top: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgb(220, 222, 226);

  span {
    margin-right: 10px;
  }
}

.footer-kuai {
  ul {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    color: #909399;
    margin-top: 20px;

    li {
      width: 20%;
      font-size: 14px;
      margin-bottom: 10px;
      //text-align: center;
      margin-right: 10px;
      //vertical-align: middle;
      .el-button {
        //margin-top: 18px;
      }

      span {
        display: inline-block;
        margin-bottom: 10px;
      }
    }

    .el-button-box {
      //ext-align: center; t
      display: flex;
      align-items: flex-end

    }
  }
}

.el-table {
  margin-top: 10px;

  /deep/ .is-leaf {
    text-align: center;
  }

  /deep/ .cell {
    text-align: center;

  }
}
</style>
